package org.cloud.consumer.controller;

import lombok.extern.slf4j.Slf4j;
import org.cloud.consumer.service.AsyncService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hjx
 * @title: AsyncController
 * @description: TODO
 * @date 2022/8/5
 */
@Slf4j
@RestController
@RequestMapping("async")
public class AsyncController {
    @Resource
    private AsyncService asyncService;

    @RequestMapping("/submit")
    public String submit(){
        log.info("start submit");

        //调用service层的任务
        for (int i = 0; i < 100; i++) {
            asyncService.executeAsync(i)
                    .thenAccept(item->{
                        System.out.println("callback====>"+item);
                    });
        }

        log.info("end submit");

        return "success";
    }

}
